package com.kmist.xiakexing.main;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.kmist.xiakexing.R;
import com.kmist.xiakexing.main.base.BaseApplication;
import com.kmist.xiakexing.main.socket.SockPresenter;

public class ITApplication extends BaseApplication {

    private Button connect;
    private Button disconnect;
    private Button send;
    private TextView status;
    private TextView sendText;
    private TextView recvText;
    private SockPresenter sockPresenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.interface_test);
        init_view();
    }

    private void init_view() {
        connect = findViewById(R.id.connect);
        disconnect = findViewById(R.id.disconnect);
        send = findViewById(R.id.send);

        status = findViewById(R.id.status);
        sendText = findViewById(R.id.input);
        recvText = findViewById(R.id.output);

        connect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sockPresenter = SockPresenter.getInstance();
                sockPresenter.connect();
            }
        });

        disconnect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String msg = sendText.getText().toString();
                sockPresenter.sendMessage(msg);
            }
        });
    }
}
